﻿<datavis:TreeMap 
    x:Class="ZipSpace.ZipTreeMap"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:zipspace="clr-namespace:ZipSpace"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400"
    ItemsSource="{Binding}">

    <datavis:TreeMap.Resources>

        <LinearGradientBrush x:Key="GradientOverlay">
            <GradientStop Color="#55ffffff" Offset="0"/>
            <GradientStop Color="#00ffffff" Offset="1"/>
        </LinearGradientBrush>

        <Style x:Key="treeMapItemGridStyle" TargetType="Grid">
            <Setter Property="Background" Value="{StaticResource GradientOverlay}" />
        </Style>

        <zipspace:IsSelectedToBrushConverter x:Key="isSelectedToBrushConverter" />
        <zipspace:StringToVisibilityConverter x:Key="stringToVisibilityConverter" />

    </datavis:TreeMap.Resources>

    <datavis:TreeMap.ItemDefinition>
        <datavis:TreeMapItemDefinition ValueBinding="{Binding Size}">
            <DataTemplate>
                <Border
                    BorderBrush="Black"
                    BorderThickness="2 2 0 0"
                    Canvas.ZIndex="1">
                    <Grid>
                        <datavis:TreeMap ItemsSource="{Binding Items}">
                            <datavis:TreeMap.ItemDefinition>
                                <datavis:TreeMapItemDefinition ValueBinding="{Binding CompressedSize}">
                                    <DataTemplate>
                                        <Border
                                            BorderBrush="Gray"
                                            BorderThickness="1 1 0 0"
                                            Background="{Binding Path=IsSelected, Converter={StaticResource isSelectedToBrushConverter}}"
                                            ToolTipService.ToolTip="{Binding}"
                                            MouseLeftButtonDown="Item_MouseLeftButtonDown">
                                            <Grid Background="{StaticResource GradientOverlay}">
                                                <Viewbox Margin="3 0 3 0">
                                                    <TextBlock Text="{Binding}" FontFamily="Arial"/>
                                                </Viewbox>
                                            </Grid>
                                        </Border>
                                    </DataTemplate>
                                </datavis:TreeMapItemDefinition>
                            </datavis:TreeMap.ItemDefinition>
                        </datavis:TreeMap>
                        <Border
                            Background="#c0ffffff"
                            CornerRadius="5"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Visibility="{Binding Path=Name, Converter={StaticResource stringToVisibilityConverter}}">
                            <TextBlock
                                Text="{Binding Name}"
                                FontSize="18"
                                FontStyle="Italic"
                                FontWeight="Bold"
                                FontFamily="Arial"
                                Margin="3"
                                ToolTipService.ToolTip="{Binding Name}"/>
                        </Border>
                    </Grid>
                </Border>
            </DataTemplate>
        </datavis:TreeMapItemDefinition>
    </datavis:TreeMap.ItemDefinition>
</datavis:TreeMap>
